accomodate the deletion of QDateTime::toTime_t in Qt6.
authortsteven4 <13596209+tsteven4@users.noreply.github.com>
Tue, 12 Oct 2021 15:12:43 +0000 (09:12 -0600)
committertsteven4 <13596209+tsteven4@users.noreply.github.com>
Tue, 12 Oct 2021 15:12:43 +0000 (09:12 -0600)
src/core/datetime.h

index a334043fa04704367d1eb790409af4c3be1b0440..93b60b34f3a4248f68c3865bb12b430e590227d5 100644 (file)
@@ -23,6 +23,7 @@
 #ifndef DATETIME_H_INCLUDED_
 #define DATETIME_H_INCLUDED_
 
+#include <cstdint>
 #include <ctime>
 
 #include <QtGlobal>
@@ -59,7 +60,7 @@ public:
 
   // Temporary: Override the standard, also handle time_t 0 as invalid.
   bool isValid() const {
-    return date().isValid() && time().isValid() && toTime_t() > 0;
+    return QDateTime::isValid() && (toSecsSinceEpoch() != 0);
   }
 
   // Like toString, but with subsecond time that's included only when
@@ -71,6 +72,18 @@ public:
       return toUTC().toString(QStringLiteral("yyyy-MM-ddTHH:mm:ssZ"));
     }
   }
+
+  // QDateTime::toTime_t was deprecated in Qt5.8, and deleted in Qt6.
+  uint32_t toTime_t() const {
+    if (!QDateTime::isValid()) {
+      return -1;
+    }
+    long long secs_since_epoch = toSecsSinceEpoch();
+    if ((secs_since_epoch < 0) || (secs_since_epoch > 0xfffffffe)) {
+      return -1;
+    }
+    return secs_since_epoch;
+  }
 };
 
 } // namespace gpsbabel